﻿using System.Collections.Generic;
using System.Data;
using Microsoft.AnalysisServices;

namespace CubeTranslationExtractor
{
    public class TranslationDataTable : DataTable
    {
        private readonly List<int> _languages;

        public TranslationDataTable()
        {
            _languages = new List<int>();
            Columns.Add("ObjectType", typeof(string));
            Columns.Add("DefaultName", typeof(string));
        }

        public void AddTranslation(string objectType, string objectDefaultCaption, int defaultLanguage,
                                   TranslationCollection translations)
        {
            DataRow row = NewRow();
            row["ObjectType"] = objectType;
            row["DefaultName"] = objectDefaultCaption;

            foreach (Translation translation in translations)
            {
                if (!_languages.Contains(translation.Language))
                {
                    _languages.Add(translation.Language);
                    Columns.Add(translation.ToString(), typeof(string));
                }
                row[translation.ToString()] = translation.Caption;
            }
            Rows.Add(row);
        }
    }
}
